import axios from 'axios'
import store from '../store/index'

//创建axios对象
const Server =axios.create({
    baseURL:'',//请求接口
    timeout:5000,//超时时间
})

//设置请求拦截器
Server.interceptors.request.use((config)=>{
    console.log(store.state.token)
    config.headers['token']=store.state.token
    return config;
},(error)=>{
    return Promise.reject(error);
})
//设置相应拦截
Server.interceptors.response.use((response)=>{
    return response;
},(error)=>{
    if(error.response.data.msg=='非法token,请先登录'){
        store.commit('log')
        this.$router.push('/login')
    }
    return Promise.reject(error);
});

//导出
export default Server
